package logic

import (
	"context"
	"gitee.com/Cauchy_AQ/vxopen/model/mongodb"
	"gitee.com/Cauchy_AQ/vxopen/rpc/wechat/internal/svc"
	"gitee.com/Cauchy_AQ/vxopen/rpc/wechat/wechat"

	"github.com/zeromicro/go-zero/core/logx"
)

type UnsubscribeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUnsubscribeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnsubscribeLogic {
	return &UnsubscribeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UnsubscribeLogic) Unsubscribe(in *wechat.UnsubscribeReq) (*wechat.UnsubscribeResp, error) {
	mongoClient := mongodb.GetMongoInstance(l.svcCtx.Config.ModelConfig)
	_, err := mongoClient.UserCol.DeleteByOpenId(context.Background(), in.Openid)
	if err != nil {
		return nil, err
	}
	return &wechat.UnsubscribeResp{}, nil
}
